/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.svc.Administrator.Users;

import com.myapp.Metodos.EncripPassword;
import com.myapp.model.DAO.Administrator.Users.AdminUserDao;
import com.myapp.model.usuarios.Usuarios;
import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 *
 * @author Tarde
 */
public class AdminUserSvc {
 
    public void deleteUser(Usuarios u)
    {
        AdminUserDao dao = new AdminUserDao();
        dao.deleteUser(u);
    }
    
    public List<Usuarios> listUser()
    {
        List lista;
        AdminUserDao dao = new AdminUserDao();
        lista = dao.listUser();
        
        return lista;
    }
        
    public Usuarios updateUser(Usuarios usr, Usuarios usr2) throws NoSuchAlgorithmException {
        EncripPassword encript = null;
        String password = null;
        
        password = usr2.getPassword();
        AdminUserDao dao = new AdminUserDao();

        if (!usr.getPassword().equals(password)) { // solo seran iguales ambas password cuando no se modifique la que estoy editando
            encript = new EncripPassword();
            password = usr.getPassword();
            
            password = encript.encripPassword(password);
            usr.setPassword(password);
        }
        /**
         * Llamada al metodo para encriptar el password
         */

        usr = dao.updateUser(usr);
        return usr;
    }
    
    
    public Usuarios buscarPorId(Usuarios usr) {
        AdminUserDao dao = new AdminUserDao();
        usr = dao.buscarPorId(usr);
        return usr;
    }
    
}
